home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2008 October / MacFormat Issue200 October 2008.toast / pc / DiscContents / In the mag / Widgets / Language Translator 1.2 / Widget / Translator.wdgt / main.js < prev    next >
Encoding:
Text File  |  2008-03-26  |  2.2 KB  |  86 lines

  1. var title = "Calories";
  2. var limit = 2500;
  3. var unit = "kcal";
  4. var current = 0;
  5.  
  6. function setup() {
  7.   if (window.widget) {
  8.     widgetSetup();
  9.     translatorSetup();
  10.     readPrefs();
  11.     widget.onremove = clearPrefs;
  12.     widget.onshow = onshow;
  13.     widget.onhide = onhide;
  14.     if (widget.context) {
  15.       //document.getElementById("Widgetop").style.display = "none";
  16.     }
  17.   }
  18. }
  19.  
  20. function readPrefs() {
  21.   if (window.widget) {
  22.     var value = widget.preferenceForKey(widget.identifier + "-source");
  23.     if (value) {
  24.       $("SourceLanguage").value = value;
  25.     }
  26.     var value = widget.preferenceForKey(widget.identifier + "-sink");
  27.     if (value) {
  28.       $("SinkLanguage").value = value;
  29.     }
  30.   }
  31. }
  32.  
  33. function clearPrefs() {
  34.   widget.setPreferenceForKey(null, widget.identifier + "-source");
  35.   widget.setPreferenceForKey(null, widget.identifier + "-sink");
  36. }
  37.  
  38. function onshow() {
  39. }
  40.  
  41. function onhide() {
  42. }
  43.  
  44. function widgetSetup() {
  45.   if (window.widget) {
  46.       var gDoneButton = new AppleGlassButton(document.getElementById("DoneButton"), 
  47.                                             "Done", hideBack); 
  48.       var gInfoButton = new AppleInfoButton(document.getElementById("InfoButton"), 
  49.                                             document.getElementById("front"), 
  50.                                             "white", "black", showBack);    
  51.   }
  52. }
  53.  
  54. function showBack() {
  55.     var front = document.getElementById("front");
  56.     var back = document.getElementById("back");
  57.  
  58.     if(window.widget)
  59.         widget.prepareForTransition("ToBack");
  60.  
  61.     front.style.display="none";
  62.     back.style.display="block";
  63.  
  64.     if (window.widget)
  65.         setTimeout ('widget.performTransition();', 0);  
  66. }
  67.  
  68. function hideBack() {
  69.     var front = document.getElementById("front");
  70.     var back = document.getElementById("back");
  71.  
  72.     if (window.widget)
  73.         widget.prepareForTransition("ToFront");
  74.  
  75.     back.style.display="none";
  76.     front.style.display="block";
  77.  
  78.     if (window.widget)
  79.         setTimeout ('widget.performTransition();', 0);
  80. }
  81.  
  82. function $(id) {
  83.   return document.getElementById(id);
  84. }
  85.  
  86. if (top.myBrowser && top.myBrowser.needsXMLHttpRequestVariable) {var XMLHttpRequest;}